package amani.wechat.platform.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import amani.wechat.platform.controller.model.CommitOrdersReturnData; 
import amani.wechat.platform.utils.WxUtils;

@Controller
@RequestMapping("/PayTest")
public class PayTestController {

	@RequestMapping("/Index")
	public String Index() {
		
		return "payTest/index";
	}
	private static Random _random = new Random();
	@RequestMapping("/Commit")
	@ResponseBody
	public	CommitOrdersReturnData commit(HttpServletRequest request) throws Exception{
		SimpleDateFormat sFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String orderno = "JJ-" + sFormat.format(new Date())
				+ _random.nextInt(1000);
		String times = "";//strtotime($opentime);
		String opendid=(String)request.getSession().getAttribute("openid");
		String clientIP=(String)request.getSession().getAttribute("clientIp");
		Double priceDouble=0.01d;
		CommitOrdersReturnData requestStatus=new CommitOrdersReturnData();   
		 //生成支付数据 
		 JSONObject payJsonData=WxUtils.GeneratePayJosn(orderno,opendid,orderno,priceDouble,clientIP);
		 requestStatus.setIsSuccessed(true); 
		 requestStatus.setPayJsonData(payJsonData);
		 return requestStatus;
		
	}
}
